
const express = require("express");
const app = express();
const router = express.Router();
const {mysql , executeQuery} = require("../../mysql");

/**
 *  查看课程接口
 */
router.get('/select-course', async (req, res) => {
    try {

        let selectQuery = `SELECT * FROM tb_course`;

        const courses = await executeQuery(selectQuery);

        console.log('courses ===', courses);

        if (courses.length > 0) {

            res.status(200).json(courses);

        } else {

            res.status(404).json({ message: 'No courses found' });
        }
    } catch (error) {

        console.error('Error fetching courses:', error);
        res.status(500).json({ message: 'Internal server error' });
    }
});

module.exports = router;
